//package com.xiangwei.util;  
//  
//import org.aspectj.lang.JoinPoint;  
//import org.aspectj.lang.annotation.*;  
//import org.slf4j.Logger;  
//import org.slf4j.LoggerFactory;  
//import org.springframework.stereotype.Component;  
//import org.springframework.web.context.request.RequestContextHolder;  
//import org.springframework.web.context.request.ServletRequestAttributes;  
//
//import com.xiangwei.dao.LogMapper;
//import com.xiangwei.entity.Customer;
//import com.xiangwei.entity.Log;
//
//import javax.annotation.Resource;  
//import javax.servlet.http.HttpServletRequest;  
//import javax.servlet.http.HttpSession;  
//
//import java.lang.reflect.Method;  
//import java.util.Date;
//  
///** 
// * 切点类 
// * @author tiangai 
// * @since 2014-08-05 Pm 20:35 
// * @version 1.0 
// */  
//@Aspect  
//@Component  
//public  class SystemLogAspect {  
//    //注入Service用于把日志保存数据库  
//	@Resource
//	private LogMapper logMapper;
//    //本地异常日志记录对象  
//     private  static  final Logger logger = LoggerFactory.getLogger(SystemLogAspect. class);  
//  
//    //Service层切点  
//    @Pointcut("@annotation(com.xiangwei.util.SystemServiceLog)")  
//     public  void serviceAspect() {  
//    }  
//  
//    //Controller层切点  
//    @Pointcut("@annotation(com.xiangwei.util.SystemControllerLog)")  
//     public  void controllerAspect() {  
//    }  
//  
//    /** 
//     * 后置通知 用于拦截Controller层记录用户的操作 
//     * 
//     * @param joinPoint 切点 
//     */  
//    @AfterReturning("controllerAspect()")  
//     public  void doBefore(JoinPoint joinPoint) {  
//        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();  
//        HttpSession session = request.getSession();  
//        //读取session中的用户  
//        Customer customer = (Customer) session.getAttribute(Const.Common.CUSTOMER_INFO);
//        //请求的IP  
//         try {  
//            //*========数据库日志=========*//  
//            Log log = new Log();
//            log.setCreateTime(new Date());
//            log.setOperateIp(CustomerIPUtil.getIpAddr(request));
//            if(customer!=null){
//            	log.setOperator(customer.getUsername());
//            }else{
//            	log.setOperator("unknow");
//            }
//            log.setContent(getControllerMethodDescription(joinPoint));
//            logMapper.insertSelective(log);
//        }  catch (Exception e) {  
//            //记录本地异常日志  
//            logger.error("==后置通知异常==");  
//            logger.error("异常信息:{}", e.getMessage());  
//        }  
//    }  
//  
//    /** 
//     * 获取注解中对方法的描述信息 用于service层注解 
//     * 
//     * @param joinPoint 切点 
//     * @return 方法描述 
//     * @throws Exception 
//     */  
//     @SuppressWarnings("rawtypes")
//	public  static String getServiceMthodDescription(JoinPoint joinPoint)  
//             throws Exception {  
//        String targetName = joinPoint.getTarget().getClass().getName();  
//        String methodName = joinPoint.getSignature().getName();  
//        Object[] arguments = joinPoint.getArgs();  
//        Class targetClass = Class.forName(targetName);  
//        Method[] methods = targetClass.getMethods();  
//        String description = "";  
//         for (Method method : methods) {  
//             if (method.getName().equals(methodName)) {  
//                Class[] clazzs = method.getParameterTypes();  
//                 if (clazzs.length == arguments.length) {  
//                    description = method.getAnnotation(SystemServiceLog. class).description();  
//                     break;  
//                }  
//            }  
//        }  
//         return description;  
//    }  
//  
//    /** 
//     * 获取注解中对方法的描述信息 用于Controller层注解 
//     * 
//     * @param joinPoint 切点 
//     * @return 方法描述 
//     * @throws Exception 
//     */  
//     @SuppressWarnings("rawtypes")
//	public  static String getControllerMethodDescription(JoinPoint joinPoint)  throws Exception {  
//        String targetName = joinPoint.getTarget().getClass().getName();  
//        String methodName = joinPoint.getSignature().getName();  
//        Object[] arguments = joinPoint.getArgs();  
//        Class targetClass = Class.forName(targetName);  
//        Method[] methods = targetClass.getMethods();  
//        String description = "";  
//         for (Method method : methods) {  
//             if (method.getName().equals(methodName)) {  
//                Class[] clazzs = method.getParameterTypes();  
//                 if (clazzs.length == arguments.length) {  
//                    description = method.getAnnotation(SystemControllerLog. class).description();  
//                     break;  
//                }  
//            }  
//        }  
//         return description;  
//    }  
//}  